Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CCIP-016 calculation script #19

Open
wants to merge 29 commits into
base: main
Choose a base branch
from
Open

Conversation

whoabuddy
Copy link
Contributor

@whoabuddy whoabuddy commented May 8, 2024

This PR includes the script used to calculate who was affected by CCIP-016 and further interpret the data. The script can be run by anyone who wishes to independently verify the data.

@whoabuddy
Copy link
Contributor Author

Update

Things are coming along, not 100% there yet but when done it's a script that anyone with NodeJS installed can run to get the same results. It uses some creative approaches to API queries that we'll likely use elsewhere, and just needs some final tuning and independent verification.

Per the CCIP, the criteria for someone to hit this bug is:

  • the user called ccd007 between the end of the cycle and the payout transaction
  • the user received citycoins back from the cycle (hits the bug / bypasses the check)
  • the contract call was successful and 0 STX were returned

Analysis

To analyze this, the script takes the following steps:

  • gets all ccd007 transactions from the API (configurable in code, saves to and retries from file)
  • gets all ccd011 transactions from the API (same)
  • gets the start/end BTC and STX block heights for each cycle (saves to and retries from file)
  • gets the payout amount, height, and number of blocks for affected window from ccd011 (saves to file)
  • gets the transactions that match the criteria for CCIP-016 per cycle
  • prints the saved cycle data, payout data, and matching transactions
  • creates a markdown table of the data for easy sharing

Examples are provided in ./examples for each file generated, and also available here

Results are stored in ./results and ignored by git.

The next step is to take those transactions and calculate what addresses were affected, and how much STX they should've received during each cycle. We have access to historical data through our Tardis contracts and can deploy something similar if needed.

To run yourself

Until this is merged you can run it by following the steps below with Node.JS installed:

  1. cloning the repo (pick one)

HTTP: git clone https://github.com/citycoins/scripts
SSH: git clone [email protected]:citycions/scripts

  1. checkout the feature branch

git checkout feat/ccip-016-calculation

  1. install the dependencies

npm install

  1. run the script

npx ts-node src/dao/ccip016-calculation.ts

The output will provide the analysis (WIP) and data files will be saved to the results folder.

Future runs of the script will read from the files to minimize API calls.

Screenshots

Loading transactions

Screenshot from 2024-05-13 09-46-22

Screenshot from 2024-05-13 09-49-50

Getting start/end block heights

Screenshot from 2024-05-13 09-46-45

Screenshot from 2024-05-13 09-50-10

Finding missed payout transactions

Screenshot from 2024-05-13 09-50-25

Example of cycle data

Screenshot from 2024-05-13 09-50-48

Example of payout data

Screenshot from 2024-05-13 09-51-01

Example of missed payout transactions
([Object] represents a transaction object)

Screenshot from 2024-05-13 09-51-47

Example of markdown output
(will be updated more)

Screenshot from 2024-05-13 09-52-42

Example of markdown output when pasted into GitHub, although the format will likely change to create a "format report" that's easy to share:

Cycle BTC Start Height BTC End Height STX Start Height STX End Height MIA Payout Height MIA Height Diff MIA Payout Amount NYC Payout Height NYC Height Diff NYC Payout Amount
54 779450 781550 97453 99112 99308 196 21738856765 99308 196 32957636028
55 781550 783650 99112 100670 100875 205 24130341569 100875 205 36583295214
56 783650 785750 100670 102356 null null null null null null
57 785750 787850 102356 104060 null null null null null null
58 787850 789950 104060 105687 null null null null null null
59 789950 792050 105687 107473 null null null null null null
60 792050 794150 107473 109189 109338 149 30143370950 109338 149 45695032162
61 794150 796250 109189 110979 111097 118 24002944424 111097 118 36386519532
62 796250 798350 110979 112809 112820 11 22341600977 112820 11 33867164794
63 798350 800450 112809 114689 114755 66 19641588871 114755 66 29773591836
64 800450 802550 114689 116486 116596 110 16622163699 116596 110 25195947330
65 802550 804650 116486 118283 118392 109 18031083017 118392 109 27330659232
66 804650 806750 118283 120101 120440 339 21136466347 120440 339 32036545780
67 806750 808850 120101 121908 122286 378 14547584045 122286 378 22049542417
68 808850 810950 121908 123725 124081 356 15092603850 124081 356 22875310501
69 810950 813050 123725 125515 126031 516 14744214112 126031 516 22346829090
70 813050 815150 125515 127251 127254 3 14562588849 127254 3 22070459358
71 815150 817250 127251 128894 129309 415 15933649223 129309 415 24147184987
72 817250 819350 128894 130575 130893 318 13140642834 130893 318 19913782531
73 819350 821450 130575 132196 132588 392 10225347415 132680 484 15495109117
74 821450 823550 132196 133807 134191 384 13547686726 134191 384 20528917568
75 823550 825650 133807 135513 135730 217 28962280296 135730 217 43886090272
76 825650 827750 135513 137300 137331 31 15681210555 137331 31 23761013666
77 827750 829850 137300 138938 138972 34 14428419333 138972 34 21862239159
78 829850 831950 138938 140625 140709 84 8354173172 140709 84 12658202794
79 831950 834050 140625 142301 142306 5 9695916112 142306 5 14691143091
80 834050 836150 142301 143989 144186 197 7891090017 144186 197 11956403387
81 836150 838250 143989 145643 145685 42 5606386687 145685 42 8494571191
82 838250 840350 145643 147282 147735 453 5912068120 147735 453 8958011022
83 840350 842450 147282 149154 149420 266 30599097204 149420 266 46365579712

@friedger or anyone proficient with SQL, can we verify the data produced by each step? I imagine there are some queries that would achieve the same goal. Verifying the examples from each step would be a bonus.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants